SUBDIRS = src samples/simple_window tests
noinst_HEADERS = Doxyfile
EXTRA_DIST = README ChangeLog TODO

lib:
	cd src; make
samples:
	cd samples; make


api-doc: 
	doxygen
	echo -ne "\\n\\n\\n API documentation can be found in doc/api/\\n\\n\\n"

man:
	echo "Not implemented yet!"


test:
	./configure --prefix /tmp CPPFLAGS="--coverage -pg"
	lcov -d tests -z
	make clean install
	if [ ! -f /tmp/lib/libsparwe.a ]; then echo "libsparwe.a was not installed!"; exit 1; fi
	if [ ! -f /tmp/include/sparwe/configreader.h ]; then echo "configreader.h was not installed!"; exit 1; fi
	if [ ! -f /tmp/include/sparwe/contentmanager.h ]; then echo "contentmanager.h was not installed!"; exit 1; fi
	if [ ! -f /tmp/include/sparwe/device.h ]; then echo "device.h was not installed!"; exit 1; fi
	if [ ! -f /tmp/include/sparwe/driver.h ]; then echo "driver.h was not installed!"; exit 1; fi
	if [ ! -f /tmp/include/sparwe/scenemanager.h ]; then echo "scenemanager.h was not installed!"; exit 1; fi
	rm -rf /tmp/lib/ /tmp/include
	cd ./tests/ && make && echo -ne "width = 800;\\nheight = 600;\\nbits = 16;\\n" > valid.conf && echo -ne ";width = 800;\\n;height = 600;\\n;bits = 16;\\n" > invalid.conf && echo && echo && echo 
	cd ./tests/ && ./test
	if [ "$?" -ne "0" ]; then exit 1; fi
	cd ..
	lcov -d tests -c --output-file lcov.info && genhtml -o doc/reports/coverage -t Sparwe lcov.info
	if [ "$?" -ne "0" ]; then echo "Could not generate coverage report."; exit 1; fi
	echo -ne "\\n\\n\\nAll tests passed! (Installation test, unit test and generation of coverage report)\\nCoverage report can be found in doc/reports/coverage/\\nNOTE: You must run configure again before install, your current install path is /tmp\\n\\n\\n"


profile:
	./configure --prefix /tmp CPPFLAGS="-pg"
	make && cd tests && ./test && gprof ./test

mem-test:
	./configure --prefix /tmp CPPFLAGS="--coverage -pg"
	cd tests && valgrind ./test



